const indexjs = {

}

// http://file.zr.miit.gov.cn/file/download?md5Path=01436421d42afba540dcae74ebfb183f@326350
//图片上传地址
var uploadUrl="http://file.zr.miit.gov.cn"

indexjs.uploadUrl=uploadUrl
//MD5校验
indexjs.md5CheckForFrontEnd = uploadUrl + '/file/md5CheckUpload';
//文件上传接口
indexjs.uploadDfs = uploadUrl + '/file/uploadDfs?identityId=admin&token=123456';

 // var mainurl='/zzf/1';//线上地址
// var mainurl='http://10.15.12.151:8083/zzf/1';//刘
// var mainurl='http://10.15.12.153:8083/zzf/1';//张
// var mainurl='http://10.15.12.161:8083/zzf/1';//梁
// var mainurl='http://10.15.12.151:8083/1';
 // var mainurl='http://zzf-hlw.guohai110.com/zzf/1'
 // var mainurl='http://zzf-hlw.zr.miit.gov.cn/zzf/1'//国海
// var mainurl='http://47.93.96.58:8010/zzf/1'
var mainurl=serverConfig.baseUrl;
indexjs.mainurl=serverConfig.baseUrl;

indexjs.get=function(url,data,success,err){
 var str=''
  $.ajax({
    url:mainurl+url+str,
    type:'get',
    headers:{
      'accesstoken': sessionStorage.getItem('policy_token')
    },
    data:data,
    xhrFields: {
      withCredentials: true
    },
    crossDomain: true,
    success:function(data){
        success(data)
        indexjs.route(data);
    },
    error:function(err){
        console.log(err)
    }
  })
}
indexjs.post2=function(url,fenye,data,success,err){
  var str="";
  data=JSON.stringify(data);
  $.ajax({
    url:mainurl+url+str,
    type:'post',
    data:data,
		headers:{
      'accesstoken': sessionStorage.getItem('policy_token')
    },
    xhrFields: {
       withCredentials: true
    },
    crossDomain: true,

    contentType:'application/json',
    success:function(data){
      success(data)
      indexjs.route(data);
    },
    error:function(err){
        console.log(err)
    }
  })
}
//xxxx-xx-xx  xx:xx:xx获取年月日
indexjs.getdata=function(data){
  if(data!=null && data!=''){
    return data.split(' ')[0]
  }else{
    return data;

  }
}

//时间差
indexjs.datecount=function(datestart,dateend){

  if(datestart,dateend){
    var timestart =Date.parse(datestart);
    var timeend = Date.parse(dateend);
    var timenow = Date.parse(new Date());
    // console.log(datestart,dateend)
    if(timestart<timenow){
      return '已截止';

    }else if(timenow<timestart){

      var cha=timestart-timenow;
      if(Math.round(cha/(24*60*60*1000))>10){

          return '生效中'
      }else{
        return '倒计时'+Math.round(cha/(24*60*60*1000))+'天'
      }
    }else{
      return '生效中'
    }
  }else{
    return '已截止';
  }


}

//中国标准时间转换为时间格式  2019-05-21;
indexjs.newTime=function(date){
    date=new Date(date);
    var time1,time2,time3,h,m,s;
    time1=date.getFullYear();
    time2=date.getMonth()+1;
    time3=date.getDate();
    if((time2+'').length<2){
        time2='0'+time2
    }
    if((time3+'').length<2){
        time3='0'+time3
    }

    h=date.getHours();
    m=date.getMinutes();
    s=date.getSeconds();
    if((h+'').length<2){
        h='0'+h
    }
    if((m+'').length<2){
        m='0'+m
    }
    if((s+'').length<2){
        s='0'+s
    }
    return time1+'-'+time2+'-'+time3
}

//时间的img切换
indexjs.dateimg=function(datestart,dateend){
  var timeend = Date.parse(dateend);
  var timestart =Date.parse(datestart);
  var timenow = Date.parse(new Date());
  if(timeend<timenow){
    return '1';
  }else if(timenow<timestart){
    var cha=timestart-timenow;
    return '2'
  }else{
    return '3'
  }
}
// 政策文件
indexjs.imgdateend=function(eTime,dTime){
    if(eTime){
      var newtime = Date.parse(new Date());
        // 开始时间
        var eTime = Date.parse(eTime);
        //截止时间
        var dTime = Date.parse(dTime);
        var cha=dTime-newtime;
        if(eTime>newtime){
          return '即将开始'
        }else{
          if(dTime){
            var num =Math.round(cha/(24*60*60*1000))
            if(cha/(24*60*60*1000)>=0){
              return '倒计时'+num+'天'
            }else{
              return '已截止'
            }
          }else{
            return '生效中'
          }
      }
    }else{
      // return '时间为空'
    }
}
// 政策文件class
indexjs.dateclass1=function(eTime,dTime){
    if(eTime){
      var newtime = Date.parse(new Date());
        // 开始时间
        var eTime = Date.parse(eTime);
        //截止时间
        var dTime = Date.parse(dTime);
        var cha=dTime-newtime;
        if(eTime>newtime){
          return 'spanyellow'
        }else{
          if(dTime){
            var num =Math.round(cha/(24*60*60*1000))
            if(cha/(24*60*60*1000)>=0){
              return 'spanyellow'
            }else{
              return 'dddddd'
            }
          }else{
            return 'spanyellow'
          }
      }
    }else{
      return 'dddddd'
    }

}
// 政策申报class
indexjs.dateclass2=function(eTime,dTime){
    if(eTime){
      var newtime = Date.parse(new Date());
        // 开始时间
        var eTime = Date.parse(eTime);
        //截止时间
        var dTime = Date.parse(dTime);
        var cha=dTime-newtime;
        if(eTime>newtime){
          return 'blue_class'
        }else{
          if(dTime){
            var num =Math.round(cha/(24*60*60*1000))
            if(cha/(24*60*60*1000)>=0){
              return 'blue_class'
            }else{
              return 'dddddd'
            }
          }else{
            return 'spanyellow'
          }
      }
    }else{
      return 'dddddd'
    }

}

//时间戳转换为时间  2019-05-21 xx:xx:xx;
indexjs.date=function(date){
    date=new Date(date*1000);
    var time1,time2,time3,h,m,s;
    time1=date.getFullYear();
    time2=date.getMonth()+1;
    time3=date.getDate();
    h=date.getHours();
    m=date.getMinutes();
    s=date.getSeconds();
    return time1+'-'+time2+'-'+time3+'  '+h+':'+m+':'+s
}
//时间戳转换为时间  2019-05-21 xx:xx:xx;
indexjs.date3=function(date){
    date=new Date(date*1000);
    var time1,time2,time3,h,m,s;
    time1=date.getFullYear();
    time2=date.getMonth()+1;
    time3=date.getDate();
    if((time2+'').length<2){
        time2='0'+time2
    }
    if((time3+'').length<2){
        time3='0'+time3
    }

    h=date.getHours();
    m=date.getMinutes();
    s=date.getSeconds();
    if((h+'').length<2){
        h='0'+h
    }
    if((m+'').length<2){
        m='0'+m
    }
    if((s+'').length<2){
        s='0'+s
    }
    return time1+'-'+time2+'-'+time3+'  '+h+':'+m+':'+s
}
// 标准时间转成时间戳
indexjs.data1=function(data){
   var newData = Date.parse(new Date(data));
   return newData
}
//时间戳转换为时间  json格式
indexjs.date2=function(date){
    var time1,time2,time3,h,m,s;
    date=new Date(date*1000);
    time1=date.getFullYear();
    time2=date.getMonth()+1;
    time3=date.getDate();
    h=date.getHours();
    m=date.getMinutes();
    s=date.getSeconds();
    return {
        time1:time1,
        time2:time2,
        time3:time3,
        h:h,
        m:m,
        s:s
    }
}
//判断滚动条有没有滑倒底部
indexjs.scroll=function(bh,mh,sh,chazhi){
    var mh=$(mh).height();
    var bh=$(bh).height();
    var sh=$(sh).scrollTop()+chazhi;
    if(bh-mh==sh){
        console.log(bh,mh,sh)
        return true;
    }
}

indexjs.date4=function(date){
        date=new Date(date);
        var time1,time2,time3,h,m,s;
        time1=date.getFullYear();
        time2=date.getMonth()+1;
        time3=date.getDate();
        if((time2+'').length<2){
            time2='0'+time2
        }
        if((time3+'').length<2){
            time3='0'+time3
        }
        return time1+'-'+time2+'-'+time3
    }
    //中国标准时间转换为时间格式  2019-05-21;
    indexjs.dates=function(date){
        date=new Date(date);
        var time1,time2,time3,h,m,s;
        time1=date.getFullYear();
        time2=date.getMonth()+1;
        time3=date.getDate();
        if((time2+'').length<2){
            time2='0'+time2
        }
        if((time3+'').length<2){
            time3='0'+time3
        }

        h=date.getHours();
        m=date.getMinutes();
        s=date.getSeconds();
        if((h+'').length<2){
            h='0'+h
        }
        if((m+'').length<2){
            m='0'+m
        }
        if((s+'').length<2){
            s='0'+s
        }
        return time1+'-'+time2+'-'+time3+' '+h+':'+m+':'+s
    }
indexjs.nowTime=function(){
  var time=new Date();
  var year=time.getFullYear();
  var mounth=time.getMonth()+1;
  var day=time.getDate();
  var week='';
  if(time.getDay()==0){
    week='日'
  }else if(time.getDay()==1){
    week='一'
  }else if(time.getDay()==2){
    week='二'
  }else if(time.getDay()==3){
    week='三'
  }else if(time.getDay()==4){
    week='四'
  }else if(time.getDay()==5){
    week='五'
  }else if(time.getDay()==6){
    week='六'
  }
  return year+'年'+mounth+'月'+day+'日 星期'+week
}
// 时分秒
indexjs.time=function(time){
      let result = parseInt(time)
  　　let h = Math.floor(result / 3600) < 10 ? '0' + Math.floor(result / 3600) : Math.floor(result / 3600)
  　　let m = Math.floor((result / 60 % 60)) < 10 ? '0' + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60))
  　　let s = Math.floor((result % 60)) < 10 ? '0' + Math.floor((result % 60)) : Math.floor((result % 60))
      result = `${h}:${m}:${s}`
      return result
}
export default indexjs;
